﻿using DoNet.ApiHttpClient;
using DoNet.ApiHttpClient.Amap;
using DoNet.Common.Helpers;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http;

namespace WebApplication1.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public class ValuesController : ApiController
    {
        private readonly AmapService amapService;
        public ValuesController()
        {
            amapService = WebApiApplication.ServiceProvider.GetService<AmapService>();
        }
        public IEnumerable<string> Get()
        {
            if (amapService != null)
            {
                Dictionary<string, object> param = new Dictionary<string, object>();
                param.Add("keywords", "");
                param.Add("subdistrict", 1);
                param.Add("key", "4e1660dbd0dbbf1da191555491267c2a");

                var response = amapService.SendRequest(HttpMethod.Get, "v3/config/district", param);
                HttpClientResponse httpClientResponse = new HttpClientResponse(response);
                httpClientResponse.GetResponseBody();
                if (httpClientResponse.IsResponse)
                {
                    if (!string.IsNullOrWhiteSpace(httpClientResponse.ResponseBody))
                    {
                        var result = JsonHelper.DeserializeObject<GaodeAreaResult>(httpClientResponse.ResponseBody);
                    }
                }
            }

            return new string[] { "value1", "value2" };
        }
    }
    /// <summary>
    /// 高德地图行政区域查询返回结果
    /// </summary>
    public class GaodeAreaResult
    {
        /// <summary>
        /// 返回结果状态值
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// 返回状态说明
        /// </summary>
        public string info { get; set; }
        /// <summary>
        /// 状态码
        /// </summary>
        public string infocode { get; set; }
        public GaodeAreaSuggestion suggestion { get; set; }
        public GaodeAreaDistrict[] districts { get; set; }
    }
    /// <summary>
    /// 行政区域查询
    /// </summary>
    public class GaodeAreaSuggestion
    {
        public string[] keywords { get; set; }
        public string[] cites { get; set; }
    }
    /// <summary>
    /// 行政区信息
    /// </summary>
    public class GaodeAreaDistrict
    {
        public object citycode { get; set; }
        public string adcode { get; set; }
        public string name { get; set; }
        public string polyline { get; set; }
        public string center { get; set; }
        public string level { get; set; }
        public GaodeAreaDistrict[] districts { get; set; }
    }
}
